local priorvars="use_above use_corr use_below"
local usevars="use_q1 use_q2 use_q4 use_q5"
local demogvars="green median_HHincome PRented income_green PBachelor"
local indvars="have_ac gas_appliances large_house high_occupancy"

local minq=0.10
local incr=0.01
*local incr=0.025
local maxq=0.90
local month=tm(2013m3)

qui gen ipw=.
qui logit T use_q1 use_q2 use_q4 use_q5 Nqtr1 Nqtr2 Nqtr3 Nqtr4 Nqtr5 Nqtr6 green median_HHincome PRented income_green PBachelor if read_month==`month'
qui predict ptmp if read_month==`month'
qui replace ipw=(T==1)*(1/ptmp)+(T==0)*(1/(1-ptmp)) if read_month==`month' 	
qui sum ipw if T==0 
local nobs0=r(N)
qui sum ipw if T==1 
local nobs1=r(N)
qui egen sum_ipw0=total(ipw) if T==0 & read_month==`month'
qui egen sum_ipw1=total(ipw) if T==1 & read_month==`month'
qui gen w_ipw=`nobs0'*ipw/sum_ipw0 if T==0 & read_month==`month'
qui replace w_ipw=`nobs1'*ipw/sum_ipw1 if T==1 & read_month==`month'
gen dailykWh_ipw=dailykWh*w_ipw if read_month==`month'
replace dailykWh=dailykWh_ipw

ivqte dailykWh (T) if read_month==`month', quantile(`minq'(`incr')`maxq') level(90)
matrix mat1=e(b)'
svmat mat1
rename mat11 estimate
gen q=`minq' if _n==1
replace q=q[_n-1]+`incr' if _n>1
keep q estimate
drop if estimate==.			





